<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="108px">
      <el-form-item label="用户名称" prop="fullName">
        <el-input v-model="queryParams.fullName" placeholder="请输入名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" v-hasPermi="['mall:area:add']" size="mini"
          @click="handleAdd(true)">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple"
          v-hasPermi="['mall:area:remove']" @click="handleDelete">删除</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="areaList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="nickName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="省" align="center" prop="province">
        <template slot-scope="scope">
          <div>{{ scope.row.province || "/" }}</div>
        </template>
      </el-table-column>
      <el-table-column label="市" align="center" prop="city">
        <template slot-scope="scope">
          <div v-if="scope.row.areaLevel == '2'">{{ scope.row.city || "/" }}</div>
          <div v-else-if="scope.row.areaLevel == '1'">{{ scope.row.city || "/" }}</div>
          <div v-else>/</div>
        </template>
      </el-table-column>
      <el-table-column label="区" align="center" prop="area">
        <template slot-scope="scope">
          <div v-if="scope.row.areaLevel == 1">{{ scope.row.area || "/" }}</div>
          <div v-else>/</div>
        </template>
      </el-table-column>
      <el-table-column label="区域级别" align="center" prop="areaLevel">
        <template slot-scope="scope">
          <div>
            {{ areaLevelArr.find((ele) => ele.areaLevel == scope.row.areaLevel).name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="区域角色" align="center" prop="areaRole">
        <template slot-scope="scope">
          <div v-if="scope.row.areaRole > 1">代理</div>
          <div v-else>客服</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['mall:area:edit']"
            @click="handleAdd(true, scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" style="color: #f00" v-hasPermi="['mall:area:remove']"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 新增和修改弹窗 -->
    <Add ref="Add" @init="getList"></Add>
  </div>
</template>

<script>
import {
  listArea,
  delArea,
} from "@/api/mall/area";
import Add from "./Add.vue";
export default {
  name: "takeawayGoods",
  dicts: ["sys_router"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 所属门店是否禁用
      isDept: true,
      // 出品部门是否禁用
      ismouth: true,
      // 非多个禁用
      multiple: true,
      // 门店列表
      storeList: [],
      // 商户列表
      merchantList: [],
      // 商品属性
      goodsAttrList: [],
      // 档口数组
      mouthList: [],
      attrIds: [],
      // 总条数
      total: 0,
      // 商城-发布商品表格数据
      areaList: [],
      areaLevelArr: [
        { name: "未知", areaLevel: 0 },
        { name: "区", areaLevel: 1 },
        { name: "市", areaLevel: 2 },
        { name: "省", areaLevel: 3 },
        // { name: "平台", areaLevel: 4 },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaRole: undefined,
        areaLevel: undefined,
        province: undefined,
        city: undefined,
        area: undefined,
        userId: undefined,
        merchantId: undefined
      },
      params: {},
      // 表单参数
      form: {},
      //判断是否商户角色
      checkMerchant: false,
      //判断是否管理员角色
      checkAdmin: false,
      //判断是否是门店角色
      checkStore: false,
      // 表单校验
      rules: {},
      // 导入
      loading1: null,
      merchantId: null,
      storeId: null,
    };
  },
  components: {
    Add,
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询区域负责人区域列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams);
      listArea(this.queryParams).then((response) => {
        this.areaList = response.rows;
        console.log(this.areaList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 页面路由字典翻译
    routerFormat(row, column) {
      return this.selectDictLabel(this.dict.type.sys_router, row);
    },
    // 点击新增
    handleAdd(type, item) {
      //数据解耦
      let data = "";
      if (item) {
        data = JSON.parse(JSON.stringify(item));
      }
      this.$refs.Add.showI(type, data);
    },

    //新增编辑组件提交成功回调
    Sonfun() {
      console.log("新增获取修改成功");
      this.getList();
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.attrIds);
      if (this.attrIds.length > 0) {
        this.queryParams.attrId = this.attrIds.join(",");
      }
      console.log(this.queryParams);
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除区域负责人区域编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delArea(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () { });
    },
  },
};
</script>

<style scoped>
.verifyStatus_0 {
  color: red !important;
}

.verifyStatus_1 {
  color: green;
}
</style>
